<template>
    <div class="goods-tabs">
      <nav>
        <a
          :class="{ active: activeName === 'GoodsDetail' }"
          href="javascript:;"
          @click="clickTab('GoodsDetail')"
        >商品详情</a>
        <a
          :class="{ active: activeName === 'GoodsEvaluate' }"
          href="javascript:;"
          @click="clickTab('GoodsEvaluate')"
        >
          <span>商品评价</span>
          <span class="evaluate-num" v-if="goodsEvaluateRef">({{ goodsEvaluateRef.total }})</span>
        </a>
      </nav>

      <GoodsDetail v-if="activeName == 'GoodsDetail'"/>
      <GoodsEvaluate ref="goodsEvaluateRef" v-if="activeName == 'GoodsEvaluate'" :goods_id="goods.id"/>
    </div>
</template>

<script setup>
import { ref } from 'vue'

import GoodsDetail from './GoodsDetail.vue'
import GoodsEvaluate from './GoodsEvaluate.vue'

defineProps({
    goods: {
        type: Object,
        default: () => {}
    }
})

// 定义评价组件ref
const goodsEvaluateRef = ref(null)


// detail-->详情   comment-->评价
const activeName = ref('GoodsDetail')
const clickTab = (name) => {
    activeName.value = name
}
</script>


<style scoped lang='scss'>
.goods-tabs {
  background: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      // padding: 0 40px;
      font-size: 18px;
      position: relative;
      padding-left: 34px;
      .evaluate-num {
        color: $price-color;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child {
        width: 140px;
        border-right: 1px solid #f5f5f5;
      }
      &:last-child {
        flex: 1;
        position: relative;
        .evaluate-num {
          position: absolute;
          top: -16px;
          left: 98px;
        }
      }
      &.active {
        &::before {
          content: "";
          position: absolute;
          left: 34px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: $main-color;
        }
      }
    }
  }
}
</style>